package com.common.vo;

import lombok.Data;

/**
 * 返回对象
 * @author yyq
 *
 */
@Data
public class ResultInfo {
	
	private Integer code; 		// 编码
	private String message; 	// 提示
	private Object data; 		// 返回的对象
	private Boolean success; 	// 返回成功状态
	private Object result; 		// 返回
	private String msg; 		// 提示


	public static final int SUCCESS_CODE_PAGE = 0;
	public static final int SUCCESS_CODE = 200;
	public static final int FAIL_CODE = 400;
	public static final int ERROR_CODE = 500;
	public static final boolean SUCCESS_TRUE = true;
	public static final boolean SUCCESS_FALSE = false;
	public static final String SUCCESS_MSG = "操作成功";
	public static final String FAIL_MSG = "操作失败";
	public static final String SUCCESS_LOADING = "加载成功";
	public static final String FAIL_LOADING = "加载失败";
	public static final String ERROR_LOADING = "异常错误";
	public static final String PARAMETER_ERROR_MSG = "参数错误";
	
	/**
	 * --------------------------------------------------------------------------------------------------
	 * 失败返回
	 * @return
	 */
	public static ResultInfo fail() {
		ResultInfo rs = new ResultInfo();
		rs.setMessage(ResultInfo.FAIL_MSG);
		rs.setCode(ResultInfo.FAIL_CODE);
		rs.setSuccess(ResultInfo.SUCCESS_FALSE);
		return rs;
	}

	public static ResultInfo fail(String msg) {
		ResultInfo rs = new ResultInfo();
		rs.setMessage(msg);
		rs.setCode(ResultInfo.FAIL_CODE);
		rs.setSuccess(ResultInfo.SUCCESS_FALSE);
		return rs;
	}

	public static ResultInfo fail(Object object) {
		ResultInfo rs = new ResultInfo();
		rs.setMessage(ResultInfo.FAIL_MSG);
		rs.setData(object);
		rs.setCode(ResultInfo.FAIL_CODE);
		rs.setSuccess(ResultInfo.SUCCESS_FALSE);
		return rs;
	}

	public static ResultInfo fail(Object object, String msg) {
		ResultInfo rs = new ResultInfo();
		rs.setMessage(msg);
		rs.setData(object);
		rs.setCode(ResultInfo.FAIL_CODE);
		rs.setSuccess(ResultInfo.SUCCESS_FALSE);
		return rs;
	}

	/**
	 * --------------------------------------------------------------------------------------------------
	 * 系统错误返回
	 * @return
	 */
	public static ResultInfo error() {
		ResultInfo rs = new ResultInfo();
		rs.setMessage(ResultInfo.ERROR_LOADING);
		rs.setCode(ResultInfo.ERROR_CODE);
		rs.setSuccess(ResultInfo.SUCCESS_FALSE);
		return rs;
	}

	public static ResultInfo error(String msg) {
		ResultInfo rs = new ResultInfo();
		rs.setMessage(msg);
		rs.setCode(ResultInfo.ERROR_CODE);
		rs.setSuccess(ResultInfo.SUCCESS_FALSE);
		return rs;
	}

	/**
	 * --------------------------------------------------------------------------------------------------
	 * 成功返回
	 * @param object
	 * @param msg
	 * @return
	 */
	public static ResultInfo success(Object object, String msg) {
		ResultInfo rs = new ResultInfo();
		rs.setMessage(msg);
		rs.setData(object);
		rs.setCode(ResultInfo.SUCCESS_CODE);
		rs.setSuccess(ResultInfo.SUCCESS_TRUE);
		return rs;
	}

	public static ResultInfo success(Object object) {
		ResultInfo rs = new ResultInfo();
		rs.setMessage(ResultInfo.SUCCESS_MSG);
		rs.setData(object);
		rs.setCode(ResultInfo.SUCCESS_CODE);
		rs.setSuccess(ResultInfo.SUCCESS_TRUE);
		return rs;
	}

	public static ResultInfo success(String msg) {
		ResultInfo rs = new ResultInfo();
		rs.setMessage(msg);
		rs.setCode(ResultInfo.SUCCESS_CODE);
		rs.setSuccess(ResultInfo.SUCCESS_TRUE);
		return rs;
	}

	public static ResultInfo success() {
		ResultInfo rs = new ResultInfo();
		rs.setMessage(ResultInfo.SUCCESS_MSG);
		rs.setCode(ResultInfo.SUCCESS_CODE);
		rs.setSuccess(ResultInfo.SUCCESS_TRUE);
		return rs;
	}
	

	/**
	 * --------------------------------------------------------------------------------------------------
	 * 自定义返回
	 * @param object
	 * @param code
	 * @param success
	 * @param msg
	 * @return
	 */
	public static ResultInfo custom(Object object, Integer code, Boolean success, String msg) {
		ResultInfo rs = new ResultInfo();
		rs.setData(object);
		rs.setCode(code);
		rs.setMessage(msg);
		rs.setSuccess(success);
		return rs;
	}

	/**
	 * --------------------------------------------------------------------------------------------------
	 * 自定义返回
	 * @param object
	 * @param success
	 * @param msg
	 * @return
	 */
	public static ResultInfo custom(Object object, Boolean success, String msg) {
		ResultInfo rs = new ResultInfo();
		rs.setResult(object);
		rs.setMsg(msg);
		rs.setSuccess(success);
		return rs;
	}


	
	
}
